package com.wn.demo06;

import java.io.PrintStream;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @author yellow Docter
 * @date 2024 -06-18
 * @desc
 *  方法的引用
 */
public class Demo01 {


    public static void main(String[] args) {

//        test01();
        Emp emp = new Emp("马云", 34);
//        String name = emp::getName;

        //lambda表达式的写法
        Supplier<String> supplier = () -> emp.getName();
        String s = supplier.get();
        System.out.println(s);

        //方法的引用写法 进一步简化了 Lambda表达式
        Supplier<String> supplier2 = emp::getName;
        String s1 = supplier2.get();
        System.out.println("s1 = " + s1);

    }

    //对象方法的引用
    private static void test01() {
        //Lambda表达式的写法
        Consumer<String> consumer = e->System.out.println(e);
        consumer.accept("Hello");

        // 方法的引用 (进一步简化了 Lambda表达式)

        PrintStream ps = System.out;
        Consumer<String> consumer2 = ps::println;
        consumer2.accept("Hello");

        Consumer<String> consumer3 = System.out::println;
        consumer3.accept("Hello");
    }

}
